//
//  LTSearchManager.m
//  LTChat
//
//  Created by 俊松何 on 2017/9/21.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import "LTSearchManager.h"
#import "LTDBHelper.h"
@implementation LTSearchResultModel



@end

@implementation LTSearchResult


@end

@implementation LTSearchManager

-(void)searchWithkeyWorld:(NSString *)keyworld
               completion:(void(^)(NSArray<LTSearchResultModel *> *userlist,LTError *lterror))CompletionBlock
{
    
    NSMutableArray *resultArray = [NSMutableArray arrayWithCapacity:10];
    
    NSArray *userarray =    [[LTDBHelper sharedbhelper] getUserWithKeyWorld:keyworld];
    if(userarray.count > 0)
    {
        NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:5];
        
        for (LTUser *user in userarray) {
            LTSearchResultModel *model = [[LTSearchResultModel alloc] init];
            model.type = LTSearchResultTypeUser;
            model.user = user;
            [tempArray addObject:model];
        }
        LTSearchResult *result = [[LTSearchResult alloc] init];
        result.title = NSLTLocalizedString(@"tabbar.contacts", nil);
        result.resultArray = tempArray;
        [resultArray addObject:result];
    }
    
    
    
    NSArray *groupArray = [[LTDBHelper sharedbhelper] getGroupWithKeyWorld:keyworld];
    if(groupArray.count > 0)
    {
        NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:5];
        for(LTGroup *group in groupArray)
        {
            LTSearchResultModel *model = [[LTSearchResultModel alloc] init];
            model.type = LTSearchResultTypeGroup;
            model.group = group;
            [tempArray addObject:model];
        }
        LTSearchResult *result = [[LTSearchResult alloc] init];
        result.title = NSLTLocalizedString(@"groupChatDetail.groups", nil);
        result.resultArray = tempArray;
        [resultArray addObject:result];
    }
    CompletionBlock(resultArray,nil);

}

@end
